package main

import (
	"fmt"
	"regexp"
	"spider/cityParser"
	"spider/engine"
)

func main() {
	/*res, err := http.Get("http://www.zhenai.com/zhenghun")
	if nil != err {
		panic(err)
	}
	mr := engine.UTF8Reader{R:res.Body}
	resultBytes := mr.TransReader()
	log.Info("请求的数据为%s",resultBytes)
	printCityList(resultBytes)*/

	parser := cityParser.CityParser{}
	fmt.Printf("%p\n", &parser)
	a := engine.Request{Url: "http://www.zhenai.com/zhenghun", Parser: &parser}
	engine.Run(&a)
}

func printCityList(content []byte) {
	//compile, _ := regexp.Compile(`<a data-v-[\w\d]+="" href="(http://www.zhenai.com/zhenghun/[\w\d]+)">([^<>]+)</a>`)
	compile, _ := regexp.Compile(`<a href="(http://www.zhenai.com/zhenghun/[\w\d]+)" data-v-[\w\d]+>([^<>]+)</a>`)
	submatch := compile.FindAllSubmatch(content, -1)
	for _, v := range submatch {
		fmt.Printf("%s", v[1])
		fmt.Printf("%s", "-")
		fmt.Printf("%s", v[2])
		fmt.Println()
	}
}
